package com.jomoo.css.common.core.model;

import com.jomoo.css.common.core.annotation.ModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
import java.util.Date;

/**
 * 公共字段基础类
 *
 * @author bo.wang
 * @version 2.0.0
 * <p>
 * name         date         desc.
 * stone.shi   2016-03-18   biz_org_id --> biz_org_code
 * remove company_id
 *
 * 在人员 信息从外部系统接入,且不太变化时,可以直接使用下面的name
 * @create 2016年3月15日 下午2:02:51
 */
@Data
@MappedSuperclass
public abstract class BaseEntity implements IModelBase, java.io.Serializable {

    @Column(name = "CREATED_BY", length = 50)
    @ModelProperty(comment = "创建人")
    String createdBy;

    @Column(name = "CREATED_BY_EN_NAME", length = 150)
    @ModelProperty(comment = "创建人")
    String createdByEnName;

    @Column(name = "CREATED_BY_NAME", length = 150)
    @ModelProperty(comment = "创建人")
    String createdByName;

    @Column(name = "CREATION_DATE")
    @ModelProperty(comment = "创建日期/时间")
    Date createDate;

    @Column(name = "LAST_UPDATED_BY", length = 50)
    @ModelProperty(comment = "修改人")
    String modifiedBy;

    @Column(name = "LAST_UPDATED_BY_ENNAME", length = 150)
    @ModelProperty(comment = "修改人")
    String modifiedByEnName;

    @Column(name = "LAST_UPDATED_BY_NAME", length = 150)
    @ModelProperty(comment = "修改人")
    String modifiedByName;

    @Column(name = "LAST_UPDATE_DATE")
    @ModelProperty(comment = "修改日期")
    Date modifiedDate;

    @Column(name = "status", length = 10)
    @ModelProperty(comment = "状态")
    String status;

    @Column(name = "OPERATION_ORG_CODE", length = 36)
    @ModelProperty(comment = "数据产生机构,")
    String operationOrgCode;

    @Column(name = "DATA_OWNER_CODE", length = 36)
    @ModelProperty(comment = "数据分区键")
    String dataOwner;

    @Column(name = "TENANT_ID", length = 36)
    @ModelProperty(comment = "数据归属")
    String tenantId;

    @Column(name = "ARCHIVE_BASE_DATE")
    @ModelProperty(comment = "归档基准日期")
    Date archiveBaseDate;

    @Version
    @Column(name = "RECORD_VERSION")
    @ModelProperty(comment = "记录版本号，每次修改记录时加1")
    Integer versionId;

    /**
     * 和mybatis @TableLogic 删除标记,1:已删除,0:正常 保持一致
     */
    @Column(name = "DEL_FLAG", length = 10)
    @ModelProperty(comment = "删除标记", des = "删除标记,1:已删除,0:正常")
    String delFlag = "0";

    @Column(name = "DELETED_BY", length = 36)
    @ModelProperty(comment = "删除人")
    String deleteBy;

    @Column(name = "DELETION_DATE", length = 36)
    @ModelProperty(comment = "删除时间")
    Date deleteDate;

    @Transient
    @ModelProperty(comment = "是否已经执行审计日志")
    boolean isLog = false;

    @Column(name = "SUB_SYSTEM", length = 100)
    @ModelProperty(comment = "子系统")
    private String subSystem;

    public abstract String getId();

    public abstract void setId(String id);
    /**
     * 重置基础字段,但不包含id
     */
    public void resetBase() {
        this.setId(null);
        this.createdByEnName = null;
        this.createdByName = null;
        this.createDate = null;
        this.modifiedBy = null;
        this.modifiedByEnName = null;
        this.modifiedByName = null;
        this.modifiedDate = null;
        this.operationOrgCode = null;
        this.dataOwner = null;
        this.tenantId = null;
        this.archiveBaseDate = null;
        this.versionId = null;
        this.delFlag = null;
        this.deleteBy = null;
        this.deleteDate = null;
        this.subSystem = null;
    }
}